// page-deviceImg/home.js
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    url:'https://www.gcjxglzx.com/upload/uploadImgTest',
    path:'',//文件本地路径
    name:'',//name文件名
    pathType:'',//自定义上传的目录路径
    identification:'',
    zhengqianfang: app.globalData.registerImage[8],
    zuoqianfang: app.globalData.registerImage[9],
    youqianfang: app.globalData.registerImage[10],
    youhoufang: app.globalData.registerImage[11],
    zuohoufang: app.globalData.registerImage[12],
    bigShelfNum:'',
    qylxr: false
  },
  getBigShelfNum:function(e){
    this.setData({
      bigShelfNum:e.detail.value
    });
  },
  uploadimg:function (e) {
    app.uploadimg(e);
  },
  chooseImage: function (e) {
    var self = this;
    wx.chooseImage({
      count: 1,
      sourceType: ['camera'],
      success: function (res) {
        if (e.target.id == '0') {
          self.setData({
            name: "zhengqianfang"
          });
          self.setData({
            zhengqianfang: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.bigShelfNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              zhengqianfang : imgResponseUrl
            })
          };
        } else if (e.target.id == '1') {
          self.setData({
            name: "zuoqianfang"
          });
          self.setData({
            zuoqianfang: res.tempFilePaths,
            path: res.tempFilePaths,
            pathType: self.data.bigShelfNum + '/' + self.data.name
          });
          app.uploadimg(self.data);
          app.imgResponseUrlReadyCallback = imgResponseUrl => {
            self.setData({
              zuoqianfang: imgResponseUrl
            })
          };
          } else if (e.target.id == '2') {
            self.setData({
              name: "youqianfang"
            });
            self.setData({
              youqianfang: res.tempFilePaths,
              path: res.tempFilePaths,
              pathType: self.data.bigShelfNum + '/' + self.data.name //拼接自定义的上传目录 设备编号/照片类型
            })
            app.uploadimg(self.data);
            app.imgResponseUrlReadyCallback = imgResponseUrl => {
              self.setData({
                youqianfang: imgResponseUrl
              })
            };
          } else if (e.target.id == '3') {
            self.setData({
              name: "youhoufang"
            });
            self.setData({
              youhoufang: res.tempFilePaths,
              name: "youhoufang",
              path: res.tempFilePaths,
              pathType: self.data.bigShelfNum + '/' + self.data.name 
            });
            app.uploadimg(self.data);
            app.imgResponseUrlReadyCallback = imgResponseUrl => {
              self.setData({
                youhoufang: imgResponseUrl
              })
            };
          } else if (e.target.id == '4') {
            self.setData({
              name: "zuohoufang"
            });
            self.setData({
              zuohoufang: res.tempFilePaths,
              path: res.tempFilePaths,
              pathType: self.data.bigShelfNum + '/' + self.data.name
            })
            app.uploadimg(self.data);
            app.imgResponseUrlReadyCallback = imgResponseUrl => {
              self.setData({
                zuohoufang: imgResponseUrl
              })
            };
          }
      }
    });
  },
  submit: function (e) {
    var that = this;
    var bigShelfNum = that.data.bigShelfNum;//设备编号
    var deviceFrontImg = that.data.zhengqianfang; //设备正前方
    var deviceFrontRightImg = that.data.youqianfang;
    var deviceFrontLiftImg = that.data.zuoqianfang;
    var deviceLiftAfterImg = that.data.zuohoufang;
    var deviceRightAfterImg = that.data.youhoufang;
    wx.request({
      url: 'https://www.gcjxglzx.com/deviceImg/save',
      method: 'POST',
      data: {
        bigShelfNum: bigShelfNum, //设备编号
        deviceFrontImg: deviceFrontImg, //设备正前方
        deviceFrontRightImg: deviceFrontRightImg, //设备右前方
        deviceFrontLiftImg: deviceFrontLiftImg,//设备左前方
        deviceLiftAfterImg: deviceLiftAfterImg,//设备左后方
        deviceRightAfterImg: deviceRightAfterImg//设备右后方
      },
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function (res) {
      console.log(res.data)
      if (res.data.status == '0') {
        wx.navigateTo({
          url: '/page-billOfDocumentImg/bodImg-home',
        })
      }
    }
  })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    that.setData({
      bigShelfNum: wx.getStorageSync("factoryNum")
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }  
})